package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_boot.dto.FileDTO;
import com.yxw.live_vod_boot.service.FileService;
import com.yxw.live_vod_boot.vo.YxFileVo;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author liuxin
 * 2023.10.07
 * 文件管理
 */
@RestController
@RequestMapping("/file")
@Api(value = "文件管理", tags = "文件管理")
@Slf4j
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping(value = "/upload_file")
    @ApiOperation(value = "上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form",name = "multipartFiles", value = "文件流结集合", required = true, dataType = "__file",allowMultiple = true),
            @ApiImplicitParam(name = "objId", value = "图片对应主体的ID", required = true),
            @ApiImplicitParam(name = "classify", value = "文件类型：1-视频 2：图片/文件", required = true),
            @ApiImplicitParam(name = "remark", value = "备注", required = true)
    })
    public BaseResult<List<YxFileVo>> uploadFile(@RequestParam("multipartFiles") MultipartFile[] multipartFiles,
                                                 @RequestParam("objId") Long objId,
                                                 @RequestParam("classify") Integer classify,
                                                 @RequestParam("remark") String remark){
        List<YxFileVo> fileList=fileService.uploadFile(multipartFiles,objId,classify,remark);
        return BaseResult.doSuccess(fileList,"上传成功");
    }

    @DeleteMapping(value = "/deleteFile")
    @ApiOperation(value = "文件删除")
    public BaseResult<Boolean> deleteFile(@RequestBody FileDTO dto) {
        fileService.deleteFile(dto);
        return BaseResult.doSuccess(null,"删除成功");
    }

    @ApiOperation(value = "文件下载/预览")
    @PostMapping(value = "/downloadFile")
    public BaseResult<String> downloadFile(@RequestBody FileDTO Dto){
        String path = fileService.downloadFile(Dto);
        return BaseResult.doSuccess(path,"下载成功");
    }

    @ApiOperation(value = "获取对应业务ID的文件信息列表")
    @PostMapping(value = "/getFileListByBussId")
    public BaseResult<List<YxFileVo>> getFileListByBussId(@RequestParam("bussId") Long bussId){
        List<YxFileVo> list = fileService.getFileListByBussId(bussId);
        return BaseResult.doSuccess(list,"查询成功");
    }
}
